package com.lisn.opengl.widget;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.util.AttributeSet;
import android.view.SurfaceHolder;

import androidx.annotation.RequiresApi;


/**
 * @author : lishan
 * @e-mail : cnlishan@163.com
 * @date : 2020/8/24 11:03 AM
 * @desc :
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class MySurfaceView extends GLSurfaceView {

    private MyRender render;

    public MySurfaceView(Context context) {
        this(context, null);
    }

    public MySurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        //1.配置EGL版本（必须配置）
        setEGLContextClientVersion(2);

        //2.设置渲染器
        render = new MyRender(this);
        setRenderer(render);

        //3.设置渲染模式
        // RENDERMODE_WHEN_DIRTY :按需渲染（手动渲染）需要手动调用 glSurfaceView.requestRender() 才会进行更新
        // RENDERMODE_CONTINUOUSLY :连续渲染（自动渲染）
        setRenderMode(RENDERMODE_WHEN_DIRTY);
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        super.surfaceDestroyed(holder);
        render.onDestroy();
    }
}
